package net.huashitong.synthetical.TaskJob.dao;

import com.alibaba.druid.sql.visitor.functions.If;
import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.entity.StringEntity;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.TaskJob.Entity.TaskProcess;
import net.huashitong.synthetical.TaskJob.filter.TaskProcessFilter;
import org.springframework.stereotype.Repository;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.List;

@Repository
public class TaskProcessDao extends StringDao<TaskProcess> {

    public List<TaskProcess> getprocessList (TaskProcessFilter filter)
    {
        GenericQuery query = createQuery("t");
        query.append(" and t.taskId=:taskId ").setParam("taskId",filter.getTaskId());
        if(StringUtils.isNotBlank(filter.getRespCode()))
        {
            query.append(" and t.respCode=:respCode").setParam("respCode",filter.getRespCode() );
        }
        if(StringUtils.isNotBlank(filter.getRespUser()))
        {
            query.append(" and t.respUser=:respUser ").setParam("respUser",filter.getRespUser());
        }
        if(StringUtils.isNotBlank(filter.getEndorseCode()))
        {
            query.append(" and t.endorseCode=:endorseCode ").setParam("endorseCode",filter.getEndorseCode());
        }
        if(StringUtils.isNotBlank(filter.getEndorseUser()))
        {
            query.append(" and t.endorseUser=:endorseUser ").setParam("endorseUser",filter.getEndorseUser());
        }
        if(StringUtils.isNotBlank(filter.getEdnorseTel() ))
        {
            query.append(" and t.endorseTel=:endorseTel").setParam("endorseTel",filter.getEdnorseTel());
        }
        if(StringUtils.isNotBlank(filter.getNodeid()) )
        {
            query.append(" and t.nodeId =:nodeId").setParam("nodeId",Integer.parseInt(filter.getNodeid()));
        }
        if(StringUtils.isNotBlank(filter.getOrderBy()))
        {
            query.append( " order by t.nodeId asc ");
        }

        return query.listResult();
    }

}
